package com.zzr.demo.redis.controller;

import com.zzr.demo.redis.service.CounterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

/**
 * @author: xiaomi
 * @date: 2021/10/7
 * @description:
 */
@RestController
@RequestMapping("same/day/log")
@Api(tags = "ID生成器：ID 自增1")
@Slf4j
public class IDGeneratorController {
    @Autowired
    @Qualifier("IDGeneratorService")
    CounterService counterService;

    @GetMapping("/init/{value}")
    @ApiOperation("初始化生成器")
    public boolean init(@PathVariable("value") int value) {
        boolean init = counterService.init(value);
        return init;
    }

    @GetMapping("/next")
    @ApiOperation("获取下一个ID 的值")
    public long next() {
        long next = counterService.increase();
        return next;
    }
}
